package com.dd.dao;

// default package

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.dd.entity.DdOrderGoods;

/**
 * A data access object (DAO) providing persistence and search support for
 * DdOrderGoods entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see .DdOrderGoods
 * @author MyEclipse Persistence Tools
 */

public class DdOrderGoodsDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(DdOrderGoodsDAO.class);
	// property constants
	public static final String ORDERID = "orderid";
	public static final String SHOPID = "shopid";
	public static final String NUM = "num";
	public static final String PRICE = "price";
	public static final String SHOPGOODSID = "shopgoodsid";

	public void save(DdOrderGoods transientInstance) {
		log.debug("saving DdOrderGoods instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(DdOrderGoods persistentInstance) {
		log.debug("deleting DdOrderGoods instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public DdOrderGoods findById(java.lang.Integer id) {
		log.debug("getting DdOrderGoods instance with id: " + id);
		try {
			DdOrderGoods instance = (DdOrderGoods) getSession().get(
					"DdOrderGoods", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(DdOrderGoods instance) {
		log.debug("finding DdOrderGoods instance by example");
		try {
			List results = getSession().createCriteria("DdOrderGoods").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding DdOrderGoods instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from DdOrderGoods as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByOrderid(Object orderid) {
		return findByProperty(ORDERID, orderid);
	}

	public List findByShopid(Object shopid) {
		return findByProperty(SHOPID, shopid);
	}

	public List findByNum(Object num) {
		return findByProperty(NUM, num);
	}

	public List findByPrice(Object price) {
		return findByProperty(PRICE, price);
	}

	public List findByShopgoodsid(Object shopgoodsid) {
		return findByProperty(SHOPGOODSID, shopgoodsid);
	}

	public List findAll() {
		log.debug("finding all DdOrderGoods instances");
		try {
			String queryString = "from DdOrderGoods";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public DdOrderGoods merge(DdOrderGoods detachedInstance) {
		log.debug("merging DdOrderGoods instance");
		try {
			DdOrderGoods result = (DdOrderGoods) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(DdOrderGoods instance) {
		log.debug("attaching dirty DdOrderGoods instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(DdOrderGoods instance) {
		log.debug("attaching clean DdOrderGoods instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}